home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2504 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.7 KB

  1. Path: colossus.holonet.net!russell
  2. From: russell@news.mdli.com (Russell Blackadar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Some help with a linker error...
  5. Date: 18 Jan 1996 03:19:31 GMT
  6. Organization: HoloNet National Internet Access System: 510-704-1058/modem
  7. Message-ID: <4dke83$p7l@colossus.holonet.net>
  8. References: <00001a81+00008ede@msn.com>
  9. NNTP-Posting-Host: jubal.mdli.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Tony Bateman (Tony_Bateman@msn.com) wrote:
  13.  
  14. [deletia]
  15.  
  16. : the global variables are part of another class ASE, which is defined
  17. : in another module...
  18.  
  19. Whoa, that's your problem.  You've confused the concept of global
  20. variables with the concept of class friendship.  Totally unrelated
  21. concepts!  
  22.  
  23. You have:
  24.  
  25. : extern  int numberOfRules;
  26. : extern  fuzzyGaussFunc *pThisFuzzyFunc;
  27. : extern  fuzzyGaussFunc *pFuzzyGfunc;
  28.  
  29. For a .cpp file with these statements to link correctly, you
  30. need statements like the following in some other .cpp file:
  31.  
  32. int numberOfRules = 29;               // or whatever
  33. fuzzyGaussFunc *pThisFuzzyFunc = 0;   // or some real function?
  34. fuzzyGaussFunc *pFuzzyGfunc = 0;      // etc...
  35.  
  36. The initializations are optional, zero if unspecified.  They
  37. *cannot* be inside some class definition, and the variables
  38. cannot be members of a class.  What you did instead was to
  39. define these variables as members of a class ASE, so the
  40. linker found no globals to resolve your externs.  
  41.  
  42. By the way, if you do want them to be class members, you'll
  43. need to rethink your design.  Even a friend function must 
  44. have an object (i.e. an instantiation of the class) to use 
  45. them, unless they're static.
  46.  
  47. : void ACE2::UpdatePt()
  48. : {
  49. :     ptMinus1 = pt;
  50. :     pt = 0;
  51. :     for (int i=0; i<numberOfRules; i++)  
  52.                         ^^^^^^^^^^^^^
  53. Hmm, if this is an ASE member, you need to specify an ASE object,
  54. e.g.
  55.         ASE some_object;      // construct an object
  56.         for (int i=0; i<some_object.numberOfRules; i++) ...
  57.  
  58. which might not make sense for you.  What should the ASE object
  59. be here, and if none makes sense, why is numberOfRules a member 
  60. of ASE at all?  Perhaps it should be a static member, in which
  61. case you'd need
  62.  
  63.         for (int i=0; i<ASE::numberOfRules; i++) ...
  64.                         ^^^^^
  65. (Maybe that is OK for you?)  Similar considerations apply for 
  66. the other two variables in question.
  67.  
  68. : Any idea why the "_" has been appended to the variables, and what is 
  69. : happening?
  70.  
  71. Compilers often "mangle" external names, and C++ compilers routinely
  72. do so (much worse than this, for functions).  This won't get in the
  73. way if you do things right, but if you forget something, sometimes 
  74. the mangling makes it hard to tell exactly what's missing.
  75.  
  76. Good luck!
  77. --
  78. Russell Blackadar,   russell@mdli.com
  79.